package com.ccctop.crowd.util;

import lombok.Data;
import org.apache.http.HttpResponse;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Data
@ConfigurationProperties(prefix = "short.messages")
public class SmsConponent {
    private String host;
    private String path;
    private String appcode;//开通服务后 买家中心-查看AppCode


    public void sendPhoneCode(String phone, String code){
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
//        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        querys.put("content","【创信】你的验证码是："+code+"，3分钟内有效！");
        querys.put("mobile", phone);
//        bodys.put("template_id", "TPL_0001");
        System.out.println("已发送短信验证码");
        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
